//
//  GuideViewController.m
//  WisdomZhuHai
//
//  Created by Admin on 14-11-1.
//  Copyright (c) 2014年 wyd. All rights reserved.
//

#import "GuideViewController.h"
#import "AppDelegate.h"
#import "HXLCustomPageView.h"

@interface GuideViewController ()

@end

@implementation GuideViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    NSArray* imgs = @[[UIImage imageNamed:@"Guide/welcome_1.jpg"], [UIImage imageNamed:@"Guide/welcome_2.jpg"], [UIImage imageNamed:@"Guide/welcome_3.jpg"]];
    
    NSMutableArray *views = [NSMutableArray array];
    for (int i=0; i<3; i++) {
        UIImageView *imgView = [[UIImageView alloc] initWithFrame:self.view.bounds];
        imgView.image = imgs[i];
        imgView.contentMode = UIViewContentModeScaleAspectFill;
        [views addObject:imgView];
        
        if (i == 2) {
            imgView.userInteractionEnabled = YES;
            UIImage *bgImg = [UIImage imageNamed:@"Guide/aj1.png"];
            UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
            btn.frame = CGRectMake(0, 0, bgImg.size.width, bgImg.size.height);
            btn.center = CGPointMake(imgView.bounds.size.width/2, imgView.bounds.size.height - bgImg.size.height/2 - 28);
            [btn setImage:bgImg forState:UIControlStateNormal];
            [btn setImage:[UIImage imageNamed:@"Guide/aj2.png"] forState:UIControlStateHighlighted];
            [btn addTarget:self action:@selector(gotoMainPage:) forControlEvents:UIControlEventTouchDown];
            [imgView addSubview:btn];
            
            UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gotoMainPage:)];
            tapGesture.cancelsTouchesInView = NO;
            [btn addGestureRecognizer:tapGesture];
        }
    }
    
    HXLCustomPageView *pageView = [[HXLCustomPageView alloc] initPageViewWithFrame:self.view.bounds views:views selectType:HXLCustomScrollView_SelectType_None];
    [self.view addSubview:pageView];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (void)gotoMainPage:(id)sender
{
    [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithBool:YES] forKey:@"firstOpenFlag"];
    [[NSUserDefaults standardUserDefaults] synchronize];
    
    AppDelegate * appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    [appDelegate.viewController showMainView];
}

@end
